package ModelLayer;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The test class PersonTest.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class PersonTest
{
    /**
     * Default constructor for test class PersonTest
     */
    public PersonTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }

    @Test
    public void findLoanTest()
    {
        Dvd dvd1 = new Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        Copy copy1 = new Copy("1", "2013", "2000");
        dvd1.addCopy(copy1);
        Person person1 = new Person("John Ham", "Sofiendalsvej 60", "9000", "Aalborg", "10111213");
        Loan loan1 = new Loan("1", copy1, "06112014", 5);
        Loan loan2 = new Loan("2", copy1, "06112014", 5);
        Loan loan3 = new Loan("3", copy1, "06112014", 5);        
        person1.addLoan(loan1);
        assertEquals(loan1, person1.findLoan("1"));
    }

    @Test
    public void findLoanEmpty()
    {
        Person person1 = new Person("John Ham", "Sofiendalsvej 60", "9000", "Aalborg", "10111213");
        assertEquals(0, person1.getLoansSize());
        assertEquals(null, person1.findLoan("3"));
    }

    @Test
    public void deleteLoanTest()
    {
        Dvd dvd1 = new Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        Copy copy1 = new Copy("1", "2013", "2000");
        dvd1.addCopy(copy1);
        Person person1 = new Person("John Ham", "Sofiendalsvej 60", "9000", "Aalborg", "10111213");
        Loan loan1 = new Loan("1", copy1, "06112014", 5);
        person1.addLoan(loan1);
        assertEquals(1, person1.getLoansSize());
        person1.deleteLoan(loan1);
        assertEquals(0, person1.getLoansSize());
    }        

    @Test
    public void testAddLoan()
    {
        Dvd dvd1 = new Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        Copy copy1 = new Copy("1", "2013", "2000");
        dvd1.addCopy(copy1);
        Person person1 = new Person("John Ham", "Sofiendalsvej 60", "9000", "Aalborg", "10111213");
        Loan loan1 = new Loan("1", copy1, "06112014", 5);
        person1.addLoan(loan1);
        assertEquals(loan1, person1.findLoan("1"));
    }
}
